﻿<AvalonDock:DocumentContent x:Class="Dispatcher.Views.PersonView"
                            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                            xmlns:Converters="clr-namespace:Dispatcher.Converters"
                            xmlns:AvalonDock="clr-namespace:AvalonDock;assembly=AvalonDock"
                            Title="TypeView" Height="600" Width="800">

    <AvalonDock:DocumentContent.Resources>
        <Converters:LazyLoadConverter x:Key="LazyLoadConverter"/>
        <Converters:BirthdayToAgeConverter x:Key="BirthdayToAgeConverter"/>
        </AvalonDock:DocumentContent.Resources>

    <AvalonDock:DocumentContent.CommandBindings>

        </AvalonDock:DocumentContent.CommandBindings>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>


        </Grid.RowDefinitions>

        <DataGrid ItemsSource="{Binding Items}"  Name="ItemsDataGrid" AllowDrop="True"
                  AutoGenerateColumns="False" Grid.Row="1"
                  PreviewKeyDown="ItemsDataGrid_PreviewKeyDown" 
                  KeyDown="ItemsDataGrid_KeyDown" 
                  MouseMove="DocumentContent_MouseMove"
                  CellEditEnding="ItemsDataGrid_CellEditEnding">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Id" Binding="{Binding Id}" IsReadOnly="True"/>
                <DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"/>
                <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"/>
                <DataGridTextColumn Header="Patronymic" Binding="{Binding Patronymic}"/>
                <DataGridTextColumn Header="Phone" Binding="{Binding Phone}"/>
                <DataGridTemplateColumn Header="Birthday">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Birthday, StringFormat=dd.MM.yyyy}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <Grid FocusManager.FocusedElement="{Binding ElementName= BirthdayPicker}">
                                <DatePicker Name="BirthdayPicker" 
                                            SelectedDate="{Binding Path=Birthday, 
                                            ValidatesOnExceptions=true, 
                                            NotifyOnValidationError=true}" />
                            </Grid>
                        </DataTemplate>     
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Age">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Birthday, Converter={StaticResource BirthdayToAgeConverter}}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTextColumn Header="Entity State" Binding="{Binding EntityState, Mode=OneWay}" IsReadOnly="True"/>
                <DataGridTemplateColumn Header="Group">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=PersonGroup, Converter={StaticResource LazyLoadConverter}}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <Grid FocusManager.FocusedElement="{Binding ElementName= BirthdayPicker}">
                                <DataGrid Name="BirthdayPicker" 
                                            ItemsSource="{Binding Path=PersonGroup}" />
                            </Grid>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        <StackPanel >

        </StackPanel>
    </Grid>
</AvalonDock:DocumentContent>
